﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Megaman
{
    public class Animation
    {
        private int switchFrame;
        private int frameCounter;

        private bool active;

        public Rectangle position;
        public Rectangle sourceRect;
        public Vector2 amountofFrames;
        public Vector2 currentFrame;
        public Texture2D Image;
        public Color color = Color.White;

        public bool Active
        {
            get { return active; }
            set { active = value; }
        }
        public Vector2 CurrentFrame
        {
            get { return currentFrame; }
            set { currentFrame = value; }
        }
        public Rectangle Position
        {
            get { return position; }
            set { Position = value; }
        }
        public Texture2D AnimationImage
        {
            set { Image = value; }
        }
        public int FrameWidth
        {
            get { return Image.Width / (int)amountofFrames.X;}
        }
        public int FrameHeight
        {
            get { return Image.Height / (int)amountofFrames.Y; }
        }
        public void Initialize(Rectangle position, Vector2 Frames)
        {
            active = false;
            switchFrame = 60;
            this.position = position;
            this.amountofFrames = Frames;
        }
        public void Update(GameTime gameTime)
        {
            if (active)
                frameCounter += (int)gameTime.ElapsedGameTime.TotalMilliseconds;
            else
                frameCounter = 0;

            if (frameCounter >= switchFrame)
            {
                frameCounter = 0;
                currentFrame.X += FrameWidth;

                if (currentFrame.X >= Image.Width)
                {
                    currentFrame.X = 0;
                }
            }

            sourceRect = new Rectangle((int)currentFrame.X, (int)currentFrame.Y * FrameHeight, FrameWidth, FrameHeight);
        }

    }
}
